<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-view></router-view>
        <router-link to="/">页面一</router-link>
        <router-link :to="{
            name: 'page2',
            params: {
                id: 123
            }
        }">页面二</router-link>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-router.js"></script>
    <script>

        const page1 = {
            template: `
                <div>这是页面一</div>
            `
        }

        const page2 = {
            template: `
                <div>这是页面二</div>
            `,
            created() {
                console.log(this.$route);
            }
        }

        const routes = [
            {
                path: '/',
                name: 'page1',
                component: page1
            },
            {
                path: '/page2',
                name: 'page2',
                component: page2
            }
        ]

        const router = new VueRouter({
            routes
        })

        new Vue({
            el: "#app",
            router
        })
    </script>
</body>
</html>